package com.example.miscontactos.Entidades;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import BaseDeDatos.AccesoABaseDeDatos;

public class RegistracionUserWeb 
{
	private String actionId;
	private String user;
	private String pass;
	private String error;
	
	public String getUser()
	{
		return user;
	}
	
	public void setUser(String user)
	{
		this.user = user;
	}
	
	public String getPass()
	{
		return this.pass;
	}
	
	public void SetPass(String pass)
	{
		this.pass = pass;
	}
	
	public String getError()
	{
		return this.error;
	}
	
	public void SetError(String error)
	{
		this.error = error;
	}
	
	public static byte[] crearUsuarioXML(String user, String pass)
	{
		String xml = "<action id='REQUEST_RANDOM_VALUE' name='register-user'>" +
						"<action-detail>" +
							"<user username='"+ user +"' password='"+ pass +"'/>" +
						"</action-detail>" +
					  "</action>";
		return xml.getBytes();
	}
	
	public static byte[] buscarMensajes(String user, String pass, String fecha)
    {
    	SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); 
		Date date = new Date();
		
		if(fecha.equals(""))
		{
			date.setTime( date.getTime() + -5*1000*60*60*24 );
		}
		else
		{
			try {
				date = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse(fecha);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
    	String xml = "<action id='REQUEST_RANDOM_VALUE' name='get-messages'>" +
				"<action-detail>" +
					"<auth username='"+ user +"' key='"+ pass +"'></auth>" +
					"<filter type='timestamp'>" + dateFormat.format(date) + "</filter>" +
				"</action-detail>" +
			  "</action>";
    	return xml.getBytes(); 
    }
}
